#include "examples.h"



void runmcLeastR(){
	int m,n,k,state,i;
	double *A, *xorin, *noise, *y, rho;
	OPTS opt;
	double c1,c2;
	stopWatch sw;
	FUNVAL result1,result2,result3;
	m=n=100;
	k=10;
	A= (double *) malloc( sizeof(double) * m* n);
	xorin = (double *) malloc(sizeof(double) * n*k);
	noise = (double *) malloc(sizeof(double) * m*k);
	y = (double *) malloc(sizeof(double) * m*k);

	state = 2344;
	acml_randseed(state);
	acml_randn(A,m*n,0.0,1.0);

	state = 13255;
	acml_randseed(state);
	acml_randn(xorin,n*k,0.0,1.0);

	state = 333;
	acml_randseed(state);
	acml_randn(noise,m*k,0.0,1.0);
	dcopy(m*k,noise,1,y,1);

	dgemm('N','N',m,k,n,1.0,A,m,xorin,n,0.01l,y,m);

	fprintM("J:\\Thesis\\temp\\c\\A.matrix",A,m,n);
	fprintM("J:\\Thesis\\temp\\c\\y.matrix",y,m,k);
	rho = 0.1l;
	memset(A,0,m*n*sizeof(double));
	memset(y,0,m*k*sizeof(double));
	fscanM("J:\\Thesis\\temp\\c\\A.matrix",A,m,n);
	fscanM("J:\\Thesis\\temp\\c\\y.matrix",y,m,k);


	//result = leastR(A,m,n,y,0.01,0.1,100);
	printf("Enter the value of l2 regression constant:");
	scanf("%lf",&c1);
	printf("Enter the value of l1 regression constant:");
	scanf("%lf",&c2);

	initOPTS(&opt,m,n,0);
	opt.mc_k = k;
	opt.q = 2.0;
	opt.init = 2;
	opt.maxIter = 100;
	opt.nFlag = 0;
	opt.rsL2 = c1;
	opt.tFlag = 5;
	opt.rFlag = 0;

//	initNormalization(&opt,A);

	opt.mFlag=0;
	opt.lFlag =0;
	startTimer(&sw);
	result1 = mcLeastR(A,y,c2,opt);
	stopTimer(&sw);
	printf("Time taken = %lf\n",getElapsedTime(&sw));

	startTimer(&sw);
	opt.mFlag = 1;
	opt.lFlag = 0;
	result2 = mcLeastR(A,y,c2,opt);
	stopTimer(&sw);
	printf("Time taken = %lf\n",getElapsedTime(&sw));

	startTimer(&sw);
	opt.mFlag = 1;
	opt.lFlag = 1;
	result3 = mcLeastR(A,y,c2,opt);
	stopTimer(&sw);
	printf("Time taken = %lf\n",getElapsedTime(&sw));


	fprintM("J:\\Thesis\\temp\\c\\x1.1.matrix",result1.x,n,k);
	fprintM("J:\\Thesis\\temp\\c\\funVal1.1.list",result1.funVal,opt.maxIter,1);
	fprintM("J:\\Thesis\\temp\\c\\lVal1.1.list",result1.ValueL,opt.maxIter,1);
	free(result1.x);
	free(result1.funVal);
	free(result1.ValueL);

	fprintM("J:\\Thesis\\temp\\c\\x1.2.matrix",result2.x,n,k);
	fprintM("J:\\Thesis\\temp\\c\\funVal1.2.list",result2.funVal,opt.maxIter,1);
	fprintM("J:\\Thesis\\temp\\c\\lVal1.2.list",result2.ValueL,opt.maxIter,1);
	free(result2.x);
	free(result2.funVal);
	free(result2.ValueL);

	fprintM("J:\\Thesis\\temp\\c\\x1.3.matrix",result3.x,n,k);
	fprintM("J:\\Thesis\\temp\\c\\funVal1.3.list",result3.funVal,opt.maxIter,1);
	fprintM("J:\\Thesis\\temp\\c\\lVal1.3.list",result3.ValueL,opt.maxIter,1);
	free(result3.x);
	free(result3.funVal);
	free(result3.ValueL);



}

